package com.appkubes.mall.restful.application.user.account.history.controller;

import com.appkubes.cloud.config.params.paramValid.ParamValid;
import com.appkubes.common.Response;
import com.appkubes.mall.core.common.constants.MallUserAccountHistoryConstants;
import com.appkubes.mall.restful.application.user.account.account.entity.dto.AccountHistoryDTO;
import com.appkubes.mall.restful.application.user.account.account.entity.vo.AccountHistoryGetVO;
import com.appkubes.mall.restful.application.user.account.history.service.UserAccountHistoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Rongjie
 * @Date: 2020/1/13 21:54
 * @Description:
 */

@Slf4j
@Api(tags = "用户账户历史")
@RestController
@RequestMapping("/user/account/history")
public class UserAccountHistoryController {
    @Resource
    UserAccountHistoryService historyService;

    @ApiOperation("获取历史记录")
    @GetMapping("/get")
    public Response<PageInfo<AccountHistoryDTO>> get(@ParamValid AccountHistoryGetVO accountHistoryGetVO) {

        PageHelper.startPage(accountHistoryGetVO.getPage(), accountHistoryGetVO.getSize());
        List<AccountHistoryDTO> accountHistories =
                historyService.geHistory(accountHistoryGetVO.getUserKey(), MallUserAccountHistoryConstants.State.CONFIRM);
        PageInfo pageInfo = new PageInfo(accountHistories);

        return Response.success(pageInfo);
    }
}
